package com.example.stream.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.stream.kafka.out.PushMsgProducer;
import com.example.stream.pojo.Loan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

@RestController
@RequestMapping("/kafka")
public class KafkaTestController {

    @Autowired
    private PushMsgProducer pushMsgProducer;

    @RequestMapping(value = "/test1", method= {RequestMethod.POST, RequestMethod.GET})
    public String test1() {

        for (int i = 0; i < 20; i ++ ) {
            Loan loan = new Loan();
            loan.setLoanId(i);
            loan.setAmt(new BigDecimal(String.valueOf(i)));
            loan.setTerm(i);
            pushMsgProducer.handler(JSONObject.toJSONString(loan));
        }

        return "success";

    }
}
